home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / profile.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  137 lines

  1. ; $Id: profile.pro,v 1.5 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1982-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. Function profile, image, xx, yy, xstart = x0, ystart = y0, nomark = nomark
  7. ;+
  8. ; NAME:
  9. ;    PROFILE
  10. ;
  11. ; PURPOSE:
  12. ;    Extract a profile from an image.
  13. ;
  14. ; CATEGORY:
  15. ;    Image processing.
  16. ;
  17. ; CALLING SEQUENCE:
  18. ;    Result = PROFILE(Image, XX, YY)
  19. ;
  20. ; INPUTS:
  21. ;    Image:    The data array representing the image.  This array can be
  22. ;        of any type except complex.
  23. ;
  24. ; KEYWORD PARAMETERS:
  25. ;      XSTART:    The starting X location of the lower-left corner of Image.
  26. ;        If this keyword is not specified, 0 is assumed.
  27. ;
  28. ;      YSTART:    The starting Y location of the lower-left corner of Image.
  29. ;        If this keyword is not specified, 0 is assumed.
  30. ;
  31. ;     NONMARK:    Set this keyword to inhibit marking the image with the 
  32. ;        profile line.
  33. ;
  34. ; OUTPUTS:
  35. ;    PROFILE returns a floating-point vector containing the values of
  36. ;    the image along the profile line marked by the user.
  37. ;
  38. ; OPTIONAL OUTPUTS:
  39. ;    XX:    After picking the end points, XX contains the X coordinates
  40. ;        of the points along the selected profile.
  41. ;
  42. ;    YY:    After picking the end points, YY contains the Y coordinates
  43. ;        of the points along the selected profile.
  44. ;
  45. ; COMMON BLOCKS:
  46. ;    None.
  47. ;
  48. ; SIDE EFFECTS:
  49. ;    Cursor on image display is enabled.
  50. ;
  51. ; RESTRICTIONS:
  52. ;    None.
  53. ;
  54. ; PROCEDURE:
  55. ;    Allow the operator to mark two points on the
  56. ;    image display with the joystick.  Extract and
  57. ;    return the points along the line.  Optionally
  58. ;    return the X and Y values of each extracted point.
  59. ;
  60. ; EXAMPLE:
  61. ;    Display an image, select a profile and plot that profile in a new
  62. ;    window.  Create and display an image by entering:
  63. ;
  64. ;        A = BYTSCL(DIST(256))
  65. ;        TV, A
  66. ;
  67. ;    Extract a profile from the image.  Enter the following command and
  68. ;    mark two points on the image with the mouse:
  69. ;
  70. ;        R = PROFILE(A)
  71. ;
  72. ;    Create a new plotting window and plot the profile by entering:
  73. ;
  74. ;        WINDOW, /FREE
  75. ;        PLOT, R
  76. ;
  77. ;    An interactive version of this routine is available with the User
  78. ;    Library procedure PROFILES.
  79. ;
  80. ; MODIFICATION HISTORY:
  81. ;    Written, DMS, November, 1982.
  82. ;    Modified for Sun, march, 1988.
  83. ;    December 1991, KRC  Made PROFILES return XX and YY.
  84. ;       Modified:  GGS, June 1996  OPTIONAL OUTPUTS: XX and YY are type long.
  85. ;                  
  86. ;-
  87. on_error,2                      ;Return to caller if an error occurs
  88. s=size(image)
  89. sx = s[1] & sy=s[2]
  90. if n_elements(x0) le 0 then x0 = 0
  91. if n_elements(y0) le 0 then y0 = 0
  92. try: print,'Mark the two end points of the profile.'
  93. Pnt1:
  94.     CURSOR,xx,yy,1,/dev    ;Get first point
  95.     y = yy - y0
  96.     x = xx - x0
  97.     if !order ne 0 then y = sy - 1 - y ;Invert?
  98.     if (x lt 0) or (x ge sx) or (y lt 0) or (y ge sy) then begin
  99.         message, 'Point outside image', /CONTINUE
  100.         goto, pnt1
  101.         endif
  102.     print,'From: (',x,',',y,')'
  103. pnt2:
  104.     wait,.5            ;for fast displays
  105.     CURSOR,xx1,yy1,/dev    ;2nd point.
  106.     y1 = yy1 - y0
  107.     x1 = xx1 - x0 
  108.     if !order ne 0 then y1 = sy - 1 - y1 ;Invert?
  109.     if (x1 lt 0) or (x1 ge sx) or (y1 lt 0) or (y1 ge sy) then begin
  110.         message, 'Point outside image.', /CONTINUE
  111.         goto, pnt2
  112.         endif
  113.     print,'To (',x1,',',y1,')'
  114.     if not keyword_set(nomark) then $
  115.         plots,[xx,xx1],[yy,yy1],/dev,/noclip ;Draw the line
  116. ;
  117. dx = float(x1-x)        ;delta x
  118. dy = float(y1-y)
  119. n = abs(dx) > abs(dy)
  120. if n eq 0 then message, 'Zero length line.'
  121. ;
  122. r = fltarr(n+1)
  123. ;
  124. if abs(dx) gt abs(dy) then begin
  125.     if x1 ge x then s=1 else s=-1
  126.     sy = (y1-y)/abs(dx)
  127.    endif else begin
  128.     if y1 ge y then sy=1 else sy=-1
  129.     s = (x1-x)/abs(dy)
  130.    endelse
  131. ;
  132. xx = lindgen(n+1l)*long(s)+x    ;X values, make into longwords.
  133. yy = lindgen(n+1l)*long(sy)+y    ;Y values
  134. return,image[long(yy)*sx + xx]
  135. end
  136.  
  137.